import Vue from 'vue'
import store from '../../store'


export default {
    /**
     * 刷新cookie user
     */
    refreshCookieUser() {
        let cookieUser = window.localStorage.getItem(Vue.prototype.COOKIEUSER)
        if (!cookieUser) {
            cookieUser = ''
            for (let i = 0; i < 8; i++) {
                cookieUser = cookieUser + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
            }
        }
        store.dispatch('updateCookieUser', cookieUser)
    },
    /**
     * 刷新next page
     * @param to
     */
    refreshNextPage(to,from) {
        //从本地缓存中获取当前数据
        let nextPage = window.localStorage.getItem(Vue.prototype.NEXTPAGE)
        /*&& to.fullPath.indexOf("/im/chat") == -1*/
        //to/user/account/setting
        if (to.fullPath.indexOf("/to/login") == -1 && to.fullPath.indexOf("/to/regist") == -1 &&
                to.fullPath.indexOf("/wechat/") == -1 && to.fullPath.indexOf("/err") == -1
                && to.fullPath.indexOf("/to/user/account/setting") == -1) {
            store.dispatch('updateNextPage', to.fullPath);
        }
    },
    /**
     * 刷新分享者信息
     */
    refreshShareInfo() {
        //当前分享者信息
        let shareInfo = window.sessionStorage.getItem(Vue.prototype.SHAREINFO)
        if (shareInfo != 'undefined') {
            store.dispatch('updateShareInfo', JSON.parse(window.decodeURIComponent(shareInfo)))
        }
    },
    refreshPreview(to) {
        if (to.query.xPreview == undefined) {
            store.state.xPreview = false
        } else {
            store.state.xPreview = to.query.xPreview == 'true'
        }
    }
}
